package de.iritgo.skillfull.component.visitor;

import de.iritgo.skillfull.component.visual.SpriteSheetRenderComponent;

/**
 * Start a animation in all animation components
 * 
 * @author held
 *
 */
public class AnimationVisitor extends BaseVisitor 
{
	private boolean done;
	private boolean setAnimCmp;

	float rotation = -1;
	private int special;
	private boolean loop;
	private boolean continuous;
	
	public AnimationVisitor (boolean loop, boolean continuous)
	{
		this.done = false;
		this.continuous = continuous;
		this.setAnimCmp = true;
		this.loop = loop;
	}
	
	public AnimationVisitor(int special) 
	{
		this.special = special;
	}

	public boolean isDone ()
	{
		return done;
	}

	/**
	 * Start an animation in the sprite sheet render component
	 */
	public void visit (SpriteSheetRenderComponent spriteSheetRenderComponent)
	{
		// Stop all....refactor!!
		if (special == 1 || done)
		{
			spriteSheetRenderComponent.stopAnimation ();
			done = true;
			return;
		}
		
		if (setAnimCmp)
		{
			spriteSheetRenderComponent.startAnimation (false, loop, continuous);
			setAnimCmp = false;
		}
		
		done = spriteSheetRenderComponent.isPlayed ();
	}
}
